#include "./head/mainwindow.h"
#include "ui_mainwindow.h"

void MainWindow::on_previousButton_clicked()
{
    // 获取当前行
    int currentRow = ui->musicList->currentRow();

    // 上一行
    int previousRow = 0;
    if (mode == Order_Mode)
    {
        previousRow = currentRow - 1;

        if (previousRow < 0)
        {
            previousRow = ui->musicList->count() - 1;
        }
    }
    else if (mode == Random_Mode)
    {
        if (ui->musicList->count() >= 3)
        {
            do
            {
                previousRow = rand() % ui->musicList->count();
            }
            while (previousRow == currentRow);
        }
        else if (ui->musicList->count() == 2)
        {
            previousRow = currentRow == 1 ? 0 : 1;
        }
        else if (ui->musicList->count() == 1)
        {
            previousRow = currentRow;
        }
    }
    else if (mode == Circle_Mode)
    {
        previousRow = currentRow;
    }

    ui->musicList->setCurrentRow(previousRow);
}
